﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using StructureMap.AutoMocking;

namespace mesan.crosscutting.testing
{
	[TestClass]
	public class BasedOn<T> : BaseTest  where T : class
	{
		protected T Instance { get; set; }
		protected MoqAutoMocker<T> Automocker {get; set;}

		[TestInitialize]
		public void BeforeEach()
		{
			Automocker = new MoqAutoMocker<T>();

			RunBeforeTests();

			Instance = Automocker.ClassUnderTest;

			RunAfterTests();
		}

		public Mock<TInterface> GetMockFor<TInterface>() where TInterface :class
		{
			return Mock.Get(Automocker.Get<TInterface>());
		}

		public virtual void RunBeforeTests()
		{
		}

		public virtual void RunAfterTests()
		{
		}
	}
}
